package container

import "fmt"

// 存储全局变量
var GlobalVariable = make(map[string]string)

// 添加全局变量
func AddGlobalVariable(key string, value string) {
	//如果已经存在,就报错
	if _, ok := GlobalVariable[key]; ok {
		panic("The " + key + " already exists")
	}
	GlobalVariable[key] = value
}

// 修改全局变量
func ModifyGlobalVariable(key string, value string) {
	//如果不存在,就报错
	if _, ok := GlobalVariable[key]; !ok {
		panic("The " + key + " does not exist")
	}
	GlobalVariable[key] = value
}

// 获取全局变量
func GetGlobalVariable(key string) string {
	//如果不存在,就报错
	if _, ok := GlobalVariable[key]; !ok {
		panic("The " + key + " does not exist")
	}
	return GlobalVariable[key]
}

// 删除全局变量
func DeleteGlobalVariable(key string) {
	//如果不存在,就报错
	if _, ok := GlobalVariable[key]; !ok {
		panic("The " + key + " does not exist")
	}
	delete(GlobalVariable, key)
}

// 打印全局变量
func PrintGlobalVariable() {
	for k, v := range GlobalVariable {
		var str = fmt.Sprintf("%s:%v", k, v)
		fmt.Println(str)
	}
}

func IsGlobalVariable(key string) bool {
	//如果不存在,就返回false
	if _, ok := GlobalVariable[key]; !ok {
		return false
	}
	return true
}
